/******************* (C) COPYRIGHT 2022 CHU WEI TENG ***********************************************
**
**------------------ File Info ---------------------------------------------------------------------
** File name:      dwin_types_def.h
** modified Date:  2022-05-10
** Last Version:   V1.0
** Descriptions: 
** 
**------------------ Modfication  log --------------------------------------------------------------
** Date       Who            Rev        Comments
----------------------------------------------------------------------------------------------------
   22/05/10  chuwt@qq.com    V1.00      created

****************************************************************************************************/
#ifndef __DWIN_TYPES_DEF_H__
#define __DWIN_TYPES_DEF_H__

#include <stdint.h>
#include <stdio.h>

/* Public define-----------------------------------------------------------------------------------*/
#ifdef __cplusplus
#define BEGIN_C_DECLS extern "C" {
#define END_C_DECLS }
#else
#define BEGIN_C_DECLS
#define END_C_DECLS
#endif

#define return_value_if_fail(p, value)                  \
	if (!(p)) 											\
	{                                           		\
		return (value);                                 \
	}

#define return_if_fail(p)                               \
	if (!(p)) 											\
	{                                           		\
		return;                                         \
	}

#define DWIN_MIN(a, b)  ((a) < (b) ? (a) : (b))
#define DWIN_ABS(a)     ((a) < (0) ? (-a) : (a))
#define DWIN_MAX(a, b)  ((a) > (b) ? (a) : (b))
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))

#define DWIN_SWAPS(x) ( \
   (((uint16_t)(x) & 0x00FFU) << 8) | \
   (((uint16_t)(x) & 0xFF00U) >> 8))

#define DWIN_SWAPL(x) ( \
   (((uint32_t)(x) & 0x000000FFUL) << 24) | \
   (((uint32_t)(x) & 0x0000FF00UL) << 8) | \
   (((uint32_t)(x) & 0x00FF0000UL) >> 8) | \
   (((uint32_t)(x) & 0xFF000000UL) >> 24))

#define DWIN_SWAPLL(x) ( \
   (((uint64_t)(x) & 0x00000000000000FFULL) << 56) | \
   (((uint64_t)(x) & 0x000000000000FF00ULL) << 40) | \
   (((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) | \
   (((uint64_t)(x) & 0x00000000FF000000ULL) << 8) | \
   (((uint64_t)(x) & 0x000000FF00000000ULL) >> 8) | \
   (((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) | \
   (((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) | \
   (((uint64_t)(x) & 0xFF00000000000000ULL) >> 56))

/* Public typedef----------------------------------------------------------------------------------*/

typedef enum _ret_t 
{
    RET_OK = 0,                                      /* 成功 */
    RET_FAIL,                                        /* 失败 */
    RET_BAD_PARAMS                                   /* 无效参数 */
} ret_t;

#endif
